Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize useQuery result handling #11954

Merged
merged 11 commits into from
Jul 15, 2024
Merged

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Jul 12, 2024

This gets rid of useHandleSkip, which mutated results during render, among a few other optimizations. Please review Commit by Commit.

Coverage shows that this code path was never hit - in the case of a `standby` fetchPolicy, `resultData.current` would already have been reset in `useResubscribeIfNecessary`
While there are three code paths to `toQueryResult`, the other two are guaranteed to never have an `errors` property
instead, we calculate and memoize an "override result" in `useObservableSubscriptionResult`
Copy link

changeset-bot bot commented Jul 12, 2024

🦋 Changeset detected

Latest commit: 2456a9a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jul 12, 2024

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 39.22 KB (-0.11% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 47.97 KB (-0.07% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 45.51 KB (-0.04% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 34.38 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 32.23 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.26 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.24 KB (0%)
import { useQuery } from "dist/react/index.js" 5.22 KB (-0.38% 🔽)
import { useQuery } from "dist/react/index.js" (production) 4.3 KB (-0.34% 🔽)
import { useLazyQuery } from "dist/react/index.js" 5.7 KB (-0.24% 🔽)
import { useLazyQuery } from "dist/react/index.js" (production) 4.77 KB (-0.33% 🔽)
import { useMutation } from "dist/react/index.js" 3.62 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.85 KB (0%)
import { useSubscription } from "dist/react/index.js" 4.41 KB (-0.09% 🔽)
import { useSubscription } from "dist/react/index.js" (production) 3.46 KB (-0.12% 🔽)
import { useSuspenseQuery } from "dist/react/index.js" 5.5 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.16 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 5 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.65 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.07 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.72 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.39 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.34 KB (0%)
import { useFragment } from "dist/react/index.js" 2.32 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.27 KB (0%)

Copy link

netlify bot commented Jul 12, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 2456a9a
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/6694da9f702c510008e1ba2a
😎 Deploy Preview https://deploy-preview-11954--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@phryneas phryneas force-pushed the pr/useQuery-result-handling branch from 0eaf524 to 4161379 Compare July 12, 2024 13:30
@phryneas phryneas marked this pull request as ready for review July 12, 2024 13:32
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had one minor comment about including a changeset, but the change looks great!

* @deprecated This property will be removed in a future version of Apollo Client.
* Please use `error.graphQLErrors` instead.
*/
errors?: ReadonlyArray<GraphQLFormattedError>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a changeset for this change? I think we're fine without one for the refactor changes, but since this is external facing, it would be great to call this out 🙂

Comment on lines 64 to 68
interface InternalQueryResult<TData, TVariables extends OperationVariables>
extends Omit<
QueryResult<TData, TVariables>,
Exclude<keyof ObservableQueryFields<TData, TVariables>, "variables">
> {
[originalResult]: ApolloQueryResult<TData>;
}
> {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Since this is now empty, can we convert this to a type and assign to it rather than extend?

type InternalQueryResult<TData, TVariables extends OperationVariables> = Omit<
  QueryResult<TData, TVariables>,
  Exclude<keyof ObservableQueryFields<TData, TVariables>, "variables">
>

@github-actions github-actions bot added the auto-cleanup 🤖 label Jul 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants